package org.vacoor.nothing.shop.controller;

import com.google.common.collect.Maps;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.vacoor.nothing.web.util.servlet.Cookie;
import org.vacoor.nothing.web.util.servlet.SimpleCookie;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 */
@RequestMapping("cart")
public class CartController {

    /*
    TB JSONP
    item_id:40588808163
    bankfrom:
    outer_id:65250819583
    outer_id_type:2
    quantity:1
    opp:1080.00
    nekot:1419183872359
    ct:4bec5458b36aa6ad3588144dec16b88a
    _tb_token_:HOj2vlwmlyUZbKA

	TB.Detail.CartResult = {
	        "error": "无法添加购物车,请登录后重试!"
	,"errorCode":"NEED_LOGIN"	    }
	// 需要登录时不知道是肿么就搞到下面了
			    TB.Detail.CartResult = {
	        "cartQuantity": "3",
	        "cartPrice": "2160.00"
	    }
     */

    @ResponseBody
    @RequestMapping("add")
    public Map<String, Object> add(String sbs, String type, int qty) {
        // 前者返回添加的商品, 后者返回所有
        // jsonp1419181536617({"cart":[{"productType":"1","quantity":1,"skuId":1743}],"success":true})
        Cookie cookie = new SimpleCookie("xx");
//        RequestContextHolder.currentRequestAttributes().
        return Maps.newHashMap();
    }


    // /car/shoppingCart 获取所有购物车信息jsonp
    // /order/shoppingCart/cart.json
    // /product/recommend?skuid=123&skuid=123  获取所有感兴趣的商品jsonp

    private Cookie cookie;

    public void onLogin(HttpServletRequest request, HttpServletResponse response) {
        String json = cookie.readValue(request, response);
        // merge
    }

    public void add2() {
        // cookie.readValue()
    }
}
